package com.b2j.routines;

import com.b2j.base.ErrorManager;
import com.b2j.base.Lexema;
import com.b2j.base.MainTools;
import com.b2j.base.Routine;
import com.b2j.base.Token;

public class SetMode extends Routine {

	@Override
	public String generate(Lexema lexema) {
		String line = "";
		String width = "";
		String height = "";
		lexema = MainTools.tools.nextLexema();
		if (lexema.tokenType == Token.OPARENT) {

			width = MainTools.tools.processCodeUntil(lexema, Token.COMMA);
			lexema = MainTools.tools.nextLexema();
			while (lexema.tokenType != Token.COMMA && lexema.tokenType != Token.CPARENT) {
				if (lexema.tokenType == Token.ID)
					height = height + MainTools.tools.identifier(lexema);
				else
					height = height + lexema.lexema;
				lexema = MainTools.tools.nextLexema();
			}
			
			// If there is a parameter next to the "HEIGHT" discard all until ")"
			if (lexema.tokenType == Token.COMMA){
				MainTools.tools.processCodeUntil(lexema, Token.CPARENT);
			}
			
		} else {
			ErrorManager.unexpected(lexema);
		}
		
		line = "JDiv.scene.setMode(" + width + "," + height + ")";
		
		MainTools.tools.screenHeight = height;
		MainTools.tools.screenWidth = width;
		
		return line;
	}

}
